package com.ftg.learn.chapter08.homework01.homework07;

import java.util.Scanner;

/**
 * 测试
 *
 * @author lijiaxin
 * @version 1.0
 * @date 2023/7/24 21:58
 */

public class Test1 {

    public static void main(String[] args) {
        Student arr[]=new Student[3];

        Student s1=new Student(4,"li",19);
        Student s2=new Student(6,"cc",21);
        Student s3=new Student(9,"xx",17);

        arr[0]=s1;
        arr[1]=s2;
        arr[2]=s3;

        for (int i = 0; i < arr.length; i++) {
            arr[i].show();
        }

//        要求1：再次添加一个学生对象，并在添加的时候进行学号的唯一性判断。

        Student s4=new Student();
        Scanner sc=new Scanner(System.in);
        System.out.println("添加学号");
        int no=sc.nextInt();
        s4.setNo(no);

        System.out.println("输入姓名");
        String name=sc.next();
        s4.setName(name);

        System.out.println("输入年龄");
        int age=sc.nextInt();
        s4.setAge(age);

        for (int i = 0; i < arr.length; i++) {
            if(s4.getNo()==arr[i].getNo()){
//                System.out.println("学号重复");
                System.out.println(s4.getNo());
                System.out.println(arr[i].getNo());
            }else {
                arr[arr.length-1]=s4;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i].show();
        }
    }
}
